In this document we are going to compare the accuracy of the spectral method and the second-order finite-difference method in the example of the cell model.
We use previously written code to calculate the analytic steady-state solution of the model and plot it in black in the following figure. We then introduce a grid of \(N=8\) points, equally spaced in log size, and represent the function in terms of only its value at those discrete points. For values at intermediate sizes we need to use an interpolation, and we plot in blue the trapezoidal interpolation (underlying the second-order numerical integration scheme) and in red the Fourier interpolation (underlying the spectral method).
We see that the Fourier interpolation is better, which is even more easily visible if we plot the difference between the actual solution and the two interpolations.
The important observation is that as the number of steps is increased, the error decreases much faster for the spectral method than for the finite-difference method. This can already be seen when we go to \(N=32\) steps.
Of course what really matters is not how well the different interpolations agree with the exact steady-state. What matters is the errors that the different methods produce when solving the cell model evolution equation.
We use the code we had written earlier for solving the cell model equation with the spectral method as well as a new variant of that function that uses a second-order finite difference method, i.e., the trapezoidal method for the integrals and the symmetric finite-difference for the first derivative.
The next figure shows the solution until time \(t=10\) when starting with an initial size distribution given by a Gaussian peak. We can see how the peak cycles through the size range repeatedly while slowly approaching the steady-state distribution. We are plotting also the \(N=32\) finite-difference approximation in blue and the \(N=32\) spectral method approximation in red.
We see that the errors from the finite-difference method quickly accummulate, but then as the system approaches the steady-state, the errors disappear again.